﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utils.Extention;
#region Version Info
/* ========================================================================
* 【本页面功能概述】
*
* 作者：wangjianfeng 创建时间：2012/9/16 12:46:42
* 文件名：News.cs
*
* 修改者： 时间：
* 修改说明：
* ========================================================================
*/
#endregion
namespace ChinaLeg.Web.News
{
    public partial class News : System.Web.UI.Page
    {
        protected string title, description, keyWrods,bgImage,adScroll;
        
        protected int catid;
        protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!this.IsPostBack)
            {
                if (!Request.QueryString["id"].IsNullOrEmpty())
                {
                    int id = Request.QueryString["id"].ToInt32();

                    ChinaLeg.Model.News model = ChinaLeg.BLL.News.Instance.GetModel(id);
                    if (model != null)
                    {
                        catid = model.CatId;

                        hlCat.Text = hlCat2.Text = ChinaLeg.Cache.Category.Instance.GetCatName(catid);
                        hlCat.NavigateUrl = hlCat2.NavigateUrl = Lib.WebLinks.GetListLinks(catid);

                        int parentcatid = ChinaLeg.Cache.Category.Instance.GetParentId(catid);

                        hlParent.Text = hlParent2.Text = ChinaLeg.Cache.Category.Instance.GetCatName(parentcatid);
                        hlParent.NavigateUrl = hlParent2.NavigateUrl = Lib.WebLinks.GetCatLinks(parentcatid);

                        litTitle.Text = model.Title;
                        litContent.Text = model.Content;
                        litDescription.Text = model.Description;

                        ChinaLeg.Model.News next = ChinaLeg.BLL.News.Instance.GetNextModel(id,catid);
                        if (next != null)
                        {
                            hlNextNews.Text = next.Title;
                            hlNextNews.NavigateUrl = Lib.WebLinks.GetNewsLinks(next.Id);
                        }
                        else
                        {
                            hlNextNews.Text = "没有了";
                        }
                        ChinaLeg.Model.News prev = ChinaLeg.BLL.News.Instance.GetPrevModel(id,catid);
                        if (prev != null)
                        {
                            hlPrevNews.Text = prev.Title;
                            hlPrevNews.NavigateUrl = Lib.WebLinks.GetNewsLinks(prev.Id);
                        }
                        else
                        {
                            hlPrevNews.Text = "没有了";
                        }

                        //List<ChinaLeg.Model.News> list = ChinaLeg.BLL.News.Instance.GetList(id);
                        //int len = list.Count % 2 == 0 ? list.Count / 2 : list.Count / 2 + 1;

                        rptPrev.DataSource = ChinaLeg.BLL.News.Instance.GetList(id);
                        rptPrev.DataBind();

                        //rptNext.DataSource = list.Skip(len);
                        //rptNext.DataBind();

                        ChinaLeg.Cache.Category.Instance.GetModel(parentcatid, out title, out  keyWrods, out  description, out  bgImage);
                        Top1.CatId = parentcatid;
                        Top1.BgImage = bgImage;
                        title = model.Title;
                        keyWrods = model.KeyWords;
                        description = model.Description;

                        rptRelation.DataSource = ChinaLeg.BLL.News.Instance.GetList(" and catid=" + catid, 15, "MidifyTime", 1);
                        rptRelation.DataBind();

                        rptCommend.DataSource = ChinaLeg.BLL.News.Instance.GetList(" and DetailsCommend=1 and catid=" + catid, 15, "ShowOrder", 0);
                        rptCommend.DataBind();

                    }
                    else
                    {
                        Response.Redirect("/");
                    }

                }
            }
        }
    }
}